package com.baiduspring.dict;

import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 频道栏目
 */
public enum ColumnChannelEnum {
    AI(1, "ai", "/css/icons/ai.svg", "人工智能"),
    BLOCK_CHAIN(2, "bc", "/css/icons/qukuailian.svg", "区块链"),
    FORE_END(3, "frontend", "/css/icons/qianduan.svg", "前端"),
    BACK_END(4, "backend", "/css/icons/houduan.svg", "后端"),
    ANDROID(5, "android", "/css/icons/Android.svg", "Android"),
    IOS(6, "ios", "/css/icons/iOS.svg", "IOS"),
    TOOLS(7, "tools", "/css/icons/gongju.svg", "工具"),
    SECURITY(8, "security", "/css/icons/anquan.svg", "安全"),
    PROGRAMMER(9, "programmer", "/css/icons/chengxuyuan.svg", "程序员"),
    INDUSTRY(10, "industry", "/css/icons/hangye.svg", "行业");

    private Integer index;
    private String label;
    private String icon;
    private String value;

    ColumnChannelEnum(Integer index, String label, String icon, String value) {
        this.index = index;
        this.label = label;
        this.icon = icon;
        this.value = value;
    }

    public static Optional<List<DictVO<Integer, String>>> columnChannels() {
        List<DictVO<Integer, String>> dictVOS = Lists.newArrayList();
        Arrays.asList(ColumnChannelEnum.values()).forEach(cc -> {
            DictVO<Integer, String> vo = new DictVO<>();
            vo.setIndex(cc.getIndex());
            vo.setLabel(cc.getLabel());
            vo.setIcon(cc.getIcon());
            vo.setValue(cc.getValue());

            dictVOS.add(vo);
        });
        return Optional.ofNullable(dictVOS);
    }

    public static Optional<ColumnChannelEnum> getColumnChannelByIndex(Integer index) {
        for (ColumnChannelEnum columnChannel : ColumnChannelEnum.values()) {
            if (columnChannel.getIndex().equals(index)) {
                return Optional.ofNullable(columnChannel);
            }
        }

        return Optional.empty();
    }

    public static Optional<ColumnChannelEnum> getColumnChannelByLabel(String label) {
        for (ColumnChannelEnum columnChannel : ColumnChannelEnum.values()) {
            if (columnChannel.getLabel().equals(label)) {
                return Optional.ofNullable(columnChannel);
            }
        }

        return Optional.empty();
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }
}
